import { defineStore } from "pinia"
import { ref } from "vue"
interface Val {
  id: string,
  icon: string,
  name: string,
  show: boolean,
}
const useTwoDialogStore = defineStore(
  // 唯一ID
  'twoDialog',
  () => {
    const list = ref<Val[]>([])

    function add(value: Val) {
        list.value.unshift(value)
    }
    function switchStatus(id: string, value: boolean, obj?: { name: string, icon: string }) {
        const key = list.value.findIndex(item => item.id === id)
        if (key !== -1) {
          list.value[key].show = value
          if (obj) {
            list.value[key].name = obj.name
            list.value[key].icon = obj.icon
          }
        }
    }
    function remove(id: string) {
        const key = list.value.findIndex(item => item.id === id)
        list.value.splice(key, 1)
    }
    function clean() {
      list.value = []
    }

    return {
      list,
      add,
      switchStatus,
      remove,
      clean,
    }
  },
)

export default useTwoDialogStore
